
<?php
Yii::import('zii.widgets.CMenu', true);
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of activeMenu
 *
 * @author sadaf.siddiqui
 */
class ActiveMenu extends CMenu
{
    public function getItems($menu_id=0, $parent_id=null){
        
        $criteria = new CDbCriteria;
        $criteria->condition = '`status` = 1';
//        $criteria->order = '`position` ASC';

//        $items = Sitemap::model()->findAll($criteria);
        
//        $results = Sitemap::model()->findAll($criteria);
//            $results->select('id, title, url')->from('{{menu_item}}');
 
        if($parent_id === null)
            
                 $criteria->condition = " parent IS NULL";
        else
                $criteria->condition =" parent=$parent_id";
 
        $criteria->order =('sort ASC');
        $results = Sitemap::model()->findAll($criteria);
 
        $items = array();
 
        if(empty($results))
                return $items;
 
        foreach($results AS $result)
        {
            $childItems=$this->getItems($menu_id, $result->id); 
            $items[] = array(
               'label'         => $result->title,
//                'active' =>1,
               'url'           => Yii::app()->createUrl($result->id0->slug),
//               'itemOptions'   =>  array('class'=>'listItem'),
               'linkOptions'   =>  array('title'=>  Helper::stripHtml($result->title)),
               'submenuOptions'=> array(),
               'items'         => $childItems, 
             );
        }
 
        return $items;
    }

    public function init()
    {
        // Here we define query conditions.
//        $criteria = new CDbCriteria;
//        $criteria->condition = '`status` = 1';
//        $criteria->order = '`position` ASC';
//
//        $items = MenuModel::model()->findAll($criteria);
//
//        foreach ($items as $item)
        
        $items=$this->getItems();
            $this->items = $items; 
//                    array(
//                                                        array('label' => 'Home<br><small>Welcome</small>', 'url' => array('/')),
//                                                        array('label' => 'About<br><small>Meet Us</small>', 'url' => array('/about')),
//                                                        array('label' => 'Services<br><small>What we offer</small>', 'url' => array('/services')),
//                                                        array('label' => 'Work<br><small>See our work</small>', 'url' => array('/work')),
//                                                        array('label' => 'F.A.Q<br><small>Get closer  </small>', 'url' => array('/faq')),
//                                                        array('label' => 'Pricing<br><small>Variations</small>', 'url' => array('/pricing')),
//                                                        array('label' => 'News<br><small>Latest Release</small>', 'url' => array('/news')),
//                                                        array('label' => 'Contact<br><small>Get in Touch</small>', 'url' => array('/contact')),
////				array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
//				array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)
//                                                    );
//            echo"<pre>";
//            print_r($this->items);
//            echo "</pre>";
            parent::init();
        
    }
    
    public function run()
        {
               $this->renderMenu($this->items);
        }
    
//    array(1) { [0]=> array(2) { [0]=> array(4) { ["label"]=> string(0) "" ["url"]=> string(4) "home" ["linkOptions"]=> array(1) { ["title"]=> string(0) "" } ["submenuOptions"]=> array(0) { } } [1]=> array(4) { ["label"]=> string(0) "" ["url"]=> string(9) "contactus" ["linkOptions"]=> array(1) { ["title"]=> string(0) "" } ["submenuOptions"]=> array(0) { } } } }
}

?>
